package com.base.controller;

import com.base.po.voip.SelfShop;
import com.base.po.voip.SelfShopCategory;
import com.base.po.voip.TourCategory;
import com.base.po.voip.Users;
import com.base.service.SelfShopCategoryService;
import com.base.service.SelfShopService;
import com.base.service.TourCategoryService;
import com.base.service.UsersService;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Controller;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RequestMethod;
import org.springframework.web.bind.annotation.ResponseBody;
import org.springframework.web.servlet.ModelAndView;

import javax.servlet.http.HttpServletRequest;
import javax.servlet.http.HttpServletResponse;
import java.util.List;

/**
 * 旅游分类
 * 
 * @author Administrator
 *
 */
@Controller
@RequestMapping("/admin")
public class index_TourCategory {
	@Autowired
	private TourCategoryService tourCategoryService;
	@Autowired
	private UsersService usersService;

	// 旅游分类首页
	@RequestMapping("/tourCategory")
	public ModelAndView index(HttpServletRequest request) throws Exception {
		// 返回ModelAndView
		ModelAndView modelAndView = new ModelAndView();
		String adminUserId = (String) request.getSession().getAttribute("adminUserId");
		Integer adminUsergrade = (Integer) request.getSession().getAttribute("adminUsergrade");
	
		Users users = usersService.selectByPrimaryKey(adminUserId);
		List<TourCategory> tourCategory = null;
		if(users.getRole() == 0 || users.getRole() == 1) {
			tourCategory = tourCategoryService.selectByLevel1(adminUserId,adminUserId);
		}
		
		request.setAttribute("tourCategory", tourCategory);
		request.setAttribute("adminUsergrade", adminUsergrade);
		// 设置页面进行跳转
		modelAndView.setViewName("jsp/index_TourCategory");
		return modelAndView;
	}
	
	//查询下级分类
//	@RequestMapping(value = "/nextCategory", method = { RequestMethod.POST, RequestMethod.GET })
//	public @ResponseBody List<SelfShopCategory> nextCategory(HttpServletRequest request, HttpServletResponse response,
//			String topid) throws Exception {
//		// 返回ModelAndView
//		response.setCharacterEncoding("utf-8");
//		response.setContentType("text/html;charset=UTF-8");
//
//		List<SelfShopCategory> nextCategorys = selfShopCategoryService.selectByTopid(topid);
//
//		if(nextCategorys != null && nextCategorys.size() > 0) {
//
//		}else {
//			nextCategorys.add(new SelfShopCategory("0", "未查询到二级分类"));
//		}
//
//		return nextCategorys;
//	}
}
